package lee.base.structure;

public class Stack<MyStructure>
{
	public static final int STACK_MAX = 20;               //define Stack of maximum size of stack
    public static final int TOP_BOTTOM = -1;              //define Stack of top pointer at stack bottom
    public static final String MSG_EMPTY = "isEmpty";     //define Stack of message : stack is empty
    public static final String MSG_FULL = "isFull";       //define Stack of message : stack is full
    public static final String MSG_STACK_EMPTY = "Null";  //define Stack of message : null stack
    public static final String MSG_SUCCESSFUL = "isOK";   //define Stack of message : do stack all right
	private MyStructure[] stack = null;  //stack
	private int top = 0;  //current top index of stack
	/* Constructor : stack */
	@SuppressWarnings("unchecked")
	public Stack(){
		//initial variables
		this.stack = (MyStructure[]) new Object[Stack.STACK_MAX];
		this.top = Stack.TOP_BOTTOM;
	}
	/* function ACT001 : push a number to stack */
	public String ACT001_push(MyStructure newEle){
		if(this.ACT004_isFull() == 1)  /* check whether stack is full */
		{
			return Stack.MSG_FULL;
		}
		this.top++;
		this.stack[this.top] = newEle;
		return Stack.MSG_SUCCESSFUL;
	}
	/* function ACT002 : pop a number from stack */
	public MyStructure ACT002_pop(){
		if(this.ACT003_isEmpty() == 1)  /* check whether stack is empty */
		{
			return null;
		}
		MyStructure result = this.GET001_element(this.top);
		this.top--;
		return result;
	}
	/* function ACT003 : check whether stack is empty now */
	public int ACT003_isEmpty(){
		if(this.top == Stack.TOP_BOTTOM)
		{
			return 1;
		}
		return 0;
	}
	/* function ACT004 : check whether stack is empty now */
	public int ACT004_isFull(){
		if(this.top == Stack.STACK_MAX - 1)
		{
			return 1;
		}
		return 0;
	}
	
	public MyStructure GET001_element(int index) {
		if(this.ACT003_isEmpty() == 1) {
			return null;
		}
		return this.stack[index];
	}
	
	public int GET002_curTopIndex() {
		return this.top;
	}
}